
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Agurto, Jorge>
-- Create date: <05/11/2011>
-- =============================================
CREATE PROCEDURE [GOOGLECODERS].PostnetBeneficiarioUpdate
	@IdBeneficiario int,
	@QueryUnions varchar(8000) = ''
AS
BEGIN
		BEGIN TRAN beneficiarioUpdate
		BEGIN TRY
				DECLARE @TableAux TABLE ( 
				IdPostnet INT NOT NULL, 
				IdBeneficiario INT NOT NULL)
				
				INSERT INTO @TableAux (IdPostnet, IdBeneficiario) 
				EXEC(@QueryUnions)
				
				DELETE FROM [GOOGLECODERS].[Postnet_x_Beneficiario]
				WHERE
					IdBeneficiario = @IdBeneficiario

				INSERT INTO [GOOGLECODERS].[Postnet_x_Beneficiario]
				SELECT IdPostnet, IdBeneficiario FROM @TableAux

				COMMIT TRAN beneficiarioUpdate
				RETURN
		END TRY
		BEGIN CATCH
				ROLLBACK TRAN beneficiarioUpdate
				RETURN
		END CATCH
END
GO